package coop.bancocredicoop.proyectos.gd;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.Query;
import coop.bancocredicoop.proyectos.gd.hibernate.HibernateUtil;
import coop.bancocredicoop.proyectos.gd.domain.Document;
import java.util.List;
import java.text.SimpleDateFormat;

public class Prueba {

	public static void metodo() {

	
	
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction tx = null;
		try {
			tx = session.beginTransaction();
			
			Query query = session.createQuery("from Document"); //You will get Weayher object
			List<Document> listDocument = query.list();
			
			for (Document document : listDocument) {

				System.out.println("Id: " + document.getId());
				System.out.println("Name: " + document.getName());
				System.out.println("Customer: " + document.getCustomer().getId());

				System.out.println("Box: " + document.getBox().getId());
				System.out.println("Tags: " + document.getTags());
				System.out.println("Document Version: " + document.getDocumentVersion());

				
				System.out.println("Real Version: " + document.getRealVersion());
				System.out.println("Last Version: " + document.getLastVersion());
				System.out.println("Valid To: " + document.getValidTo());

				System.out.println("Document Type: " + document.getDocumentType().getId());
				System.out.println("Notes: " + document.getNotes());
				System.out.println("Created Date: " + document.getCreatedDate());
				System.out.println(new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").format(document.getCreatedDate()));
				System.out.println("Last Updated: " + document.getLastUpdated());
				System.out.println("Created By User Name: " + document.getCreatedByUserName());
				
			}
			
			tx.commit();
		}
		catch (Exception e) {
			if (tx!=null) tx.rollback();
				e.printStackTrace();
		} finally {
			session.close();
		}

		System.out.println("un metodo!!!");

	}

}